<template>
  <div>
    <el-table
      ref="table"
      v-loading="crud.loading"
      border
      :data="crud.data"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      row-key="id"
      max-height="350"
      @select="crud.selectChange"
      @select-all="crud.selectAllChange"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column :show-overflow-tooltip="true" label="脚本名称" prop="fileName" min-width="180" />
      <el-table-column :show-overflow-tooltip="true" label="验证状态" prop="status" min-width="80">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 'TODO'">待验证</el-tag>
          <el-tag v-if="scope.row.status === 'SUCCESS'">成功</el-tag>
          <el-tag v-else-if="scope.row.status == 'FAIL'" type="warning">失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" label="开始时间" prop="testStartTs" min-width="140" />
      <el-table-column :show-overflow-tooltip="true" label="结束时间" prop="testEndTs" min-width="140" />
      <el-table-column :show-overflow-tooltip="true" label="操作时间" prop="crtTs" min-width="150" />
      <el-table-column :show-overflow-tooltip="true" label="验证日志" prop="testLog" min-width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showTestLog(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <div style="line-height: 20px; height: 20px;">
      <pagination />
    </div>

    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :visible.sync="showTestLogFlag"
      title="脚本验证日志"
      width="1200px"
      top="5vh"
    >
      <monaco-editor
        ref="convertMonaco"
        v-model="showTestLogContent"
        style="height: 430px"
      />
    </el-dialog>

  </div>
</template>
<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import pagination from '@crud/Pagination'
import MonacoEditor from '@/components/MonacoEditor/monacoEditor'

const defaultCrud = CRUD({ title: '脚本验证日志', url: 'api/script/convert/test/log' })
const defaultForm = {}

export default {
  name: 'ScriptVerifyHistory',
  components: { pagination, MonacoEditor },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  props: {
    convertListPkId: {
      required: true,
      type: String
    }
  },
  data() {
    return {
      showTestLogFlag: false,
      showTestLogContent: ''
    }
  },
  created() {
  },
  methods: {
    [CRUD.HOOK.beforeRefresh](crud) {
      crud.query.scriptConvertListId = this.convertListPkId
    },
    showTestLog(row) {
      this.showTestLogFlag = true
      this.showTestLogContent = row.testLog
    }
  }
}
</script>

